package de.hft_stuttgart.dsa.ctt.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;

/**
 * @author Eduard Tudenhoefner
 */
public class ProblemInstance {
	private String name;
	private int numberOfCourses = 0;
	private int numberOfRooms = 0;
	private int days = 0;
	private int periodsPerDay = 0;
	private int numberOfCurricula = 0;
	private int numberOfConstraints = 0;
	private Curricula curricula;
	private List<Room> rooms = new ArrayList<Room>();
	private List<Period> periods = new ArrayList<Period>();
	private HashMap<String, Course> allCourses;

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the numberOfCourses
	 */
	public int getNumberOfCourses() {
		return numberOfCourses;
	}

	/**
	 * @param numberOfCourse
	 *            the numberOfCourse to set
	 */
	public void setNumberOfCourse(int numberOfCourse) {
		this.numberOfCourses = numberOfCourse;
	}

	/**
	 * @return the numberOfRooms
	 */
	public int getNumberOfRooms() {
		return numberOfRooms;
	}

	/**
	 * @param numberOfRooms
	 *            the numberOfRooms to set
	 */
	public void setNumberOfRooms(int numberOfRooms) {
		this.numberOfRooms = numberOfRooms;
	}

	/**
	 * @return the days
	 */
	public int getDays() {
		return days;
	}

	/**
	 * @param days
	 *            the days to set
	 */
	public void setDays(int days) {
		this.days = days;
	}

	/**
	 * @return the periodsPerDay
	 */
	public int getPeriodsPerDay() {
		return periodsPerDay;
	}

	/**
	 * @param periodsPerDay
	 *            the periodsPerDay to set
	 */
	public void setPeriodsPerDay(int periodsPerDay) {
		this.periodsPerDay = periodsPerDay;
	}

	/**
	 * @return the numberOfCurricula
	 */
	public int getNumberOfCurricula() {
		return numberOfCurricula;
	}

	/**
	 * @param numberOfCurricula
	 *            the numberOfCurricula to set
	 */
	public void setNumberOfCurricula(int numberOfCurricula) {
		this.numberOfCurricula = numberOfCurricula;
	}

	/**
	 * @return the numberOfConstraints
	 */
	public int getNumberOfConstraints() {
		return numberOfConstraints;
	}

	/**
	 * @param numberOfConstraints
	 *            the numberOfConstraints to set
	 */
	public void setNumberOfConstraints(int numberOfConstraints) {
		this.numberOfConstraints = numberOfConstraints;
	}

	/**
	 * @param curricula
	 *            the curricula to set
	 */
	public void setCurricula(Curricula curricula) {
		this.curricula = curricula;
	}

	/**
	 * @return the curricula
	 */
	public Curricula getCurricula() {
		return curricula;
	}

	/**
	 * @return the rooms
	 */
	public List<Room> getRooms() {
		return rooms;
	}

	public List<Room> getRoomsOrderedByCapacity() {
		List<Room> capacityOrderedRooms = new ArrayList<Room>();
		capacityOrderedRooms.addAll(rooms);
		Collections.sort(capacityOrderedRooms, new Comparator<Room>() {
			@Override
			public int compare(Room course1, Room course2) {
				return course1.compareTo(course2);
			}
		});
		return capacityOrderedRooms;
	
	}
	
	/**
	 * @param rooms
	 *            the rooms to set
	 */
	public void setRooms(List<Room> rooms) {
		this.rooms = rooms;
	}

	/**
	 * @param periods
	 *            the periods to set
	 */
	public void setPeriods(List<Period> periods) {
		this.periods = periods;
	}

	/**
	 * @return the periods
	 */
	public List<Period> getPeriods() {
		return periods;
	}

	/**
	 * @param allCourses
	 *            the allCourses to set
	 */
	public void setAllCourses(HashMap<String, Course> allCourses) {
		this.allCourses = allCourses;
	}

	/**
	 * @return the allCourses
	 */
	public HashMap<String, Course> getAllCourses() {
		return allCourses;
	}

	/**
	 * @return All courses based on their decreasing priority.
	 */
	public List<Course> getPriorityBasedCourses() {
		List<Course> courses = new ArrayList<Course>();
		courses.addAll(allCourses.values());
		Collections.sort(courses, new Comparator<Course>() {
			@Override
			public int compare(Course course1, Course course2) {
				return course1.compareTo(course2);
			}
		});
		return courses;
	}
	
	@Override
	public String toString() {
		return name;
	}
}
